<template>
    <div>
      <van-field
        v-model="content"
        :label="label"
        :type="type"
        :rule="rule"

        :placeholder="placeholder" />
    </div>
</template>

<script>
    export default {
      props:['label','type','placeholder','rule'],
        name: "LoginText",
        data() {
            return {
              content:''
            }
        },
        methods: {
          handlerule(){
            //此时父组件传过来的rule正则是字符串类型的，要把它转化为真正的正则
            const rule = new RegExp(this.rule)
            if (rule.test(this.content)) {
              this.$emit('inputChange',this.content)
            }


          }
        },
      watch:{
        content(){
          this.handlerule()

        }
      }
    }
</script>

<style scoped>

</style>
